import { https } from '@/utils/https'
import type {
  OrderPreResult,
  OrderCreateParams,
  OrderResult,
  OrderLogisticResult,
  OrderListParams,
  OrderListResult,
} from '../types/order'
// 填写信息，获取预付款订单
export const getMemberOrderPreAPI = () => {
  return https<OrderPreResult>({
    method: 'GET',
    url: '/member/order/pre',
  })
}
export const getMemberOrderPreNowAPI = (data: {
  skuId: string
  count: string
  addressId?: string
}) => {
  return https<OrderPreResult>({
    method: 'GET',
    url: '/member/order/pre/now',
    data,
  })
}
// 提交订单
export const postMemberOrderAPI = (data: OrderCreateParams) => {
  return https<{ id: string }>({
    method: 'POST',
    url: '/member/order',
    data,
  })
}
// 获取订单详情
export const getMemberOrderByIdAPI = (id: string) => {
  return https<OrderResult>({
    method: 'GET',
    url: `/member/order/${id}`,
  })
}
// 正式服微信支付
export const getPayWxPayMiniPayAPI = (data: { orderId: string }) => {
  return https<WechatMiniprogram.RequestPaymentOption>({
    method: 'GET',
    url: '/pay/wxPay/miniPay',
    data,
  })
}
// 开发环境微信支付
export const getPayMockAPI = (data: { orderId: string }) => {
  return https({
    method: 'GET',
    url: '/pay/mock',
    data,
  })
}
// 模拟发货
export const getMemberOrderConsignmentByIdAPI = (id: string) => {
  return https({
    method: 'GET',
    url: `/member/order/consignment/${id}`,
  })
}
// 确认收货
export const putMemberOrderReceiptByIdAPI = (id: string) => {
  return https<OrderResult>({
    method: 'PUT',
    url: `/member/order/${id}/receipt`,
  })
}
// 获取订单物流
export const getMemberOrderLogisticsByIdAPI = (id: string) => {
  return https<OrderLogisticResult>({
    method: 'GET',
    url: `/member/order/${id}/logistics`,
  })
}
// 删除订单
export const deleteMemberOrderAPI = (data: { ids: string[] }) => {
  return https({
    method: 'DELETE',
    url: `/member/order`,
    data,
  })
}
// 获取订单列表
export const getMemberOrderAPI = (data: OrderListParams) => {
  return https<OrderListResult>({
    method: 'GET',
    url: `/member/order`,
    data,
  })
}
